#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include"SeqList.h"
#include<assert.h>
void SLInit(SL* ps)
{
	ps->a = NULL;
	ps->size = ps->capacity = 0;

}
void SLDestroy(SL* ps);
void SLPrint(SL* ps);
void SLCheckCapacity(SL* ps)
{
	assert(ps);

	if (ps->size == ps->capacity)
	{
	    ps->capacity = ps->capacity != 0 ? 2 * ps->capacity : 4;
		SLDataType* tmp = (SLDataType*)realloc(ps->a,
			ps->capacity*sizeof(SLDataType));
		if (tmp == NULL)
		{
			perror("realloc");
			return;
		}
		
		ps->a = tmp;

	}
}
void SLPushBack(SL* ps, SLDataType x)
{
	assert(ps);
	SLCheckCapacity(ps);

	ps->a[ps->size] = x;
	ps->size++;
}
void SLPopBack(SL* ps)
{
	assert(ps);
	assert(ps->size);
	ps->size--;
}
void SLPushFront(SL* ps, SLDataType x)
{
	assert(ps);

	SLCheckCapacity(ps);
	for (int i = ps->size;i >=1 ;i--)
	{
		ps->a[i] = ps->a[i - 1];
	}
	ps->a[0] = x;
	ps->size++;
}
void SLPopFront(SL* ps)
{
	assert(ps);
	assert(ps->size);
	for (int i = 0;i <= ps->size-2;i++)
	{
		ps->a[i] = ps->a[i + 1];
	}
	ps->size--;
}
void SLInsert(SL* ps, int pos, SLDataType x)
{
	assert(ps);
	SLCheckCapacity(ps);
	for (int i = ps->size;i >=pos ;i--)
	{
		ps->a[i] = ps->a[i-1];
	}
	ps->a[pos - 1] = x;
	ps->size++;

}
void SLErase(SL* ps, int pos)
{
	assert(ps);
	for (int i = pos;i < ps->size;i++)
	{
		ps->a[i - 1] = ps->a[i];
	}
	ps->size--;
}
int SLFind(SL* ps, SLDataType x)
{
	for (int i = 0;i < ps->size;i++)
	{
		if (x == ps->a[i]);
		{
			return i;
		}
	}
}




